# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=aws-sdk-cpp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.7.365
pkgrel=2
pkgdesc="AWS SDK for C++ (mingw-w64)"
arch=('any')
url="https://github.com/aws/aws-sdk-cpp"
license=('Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/aws/aws-sdk-cpp/archive/${pkgver}.tar.gz"
        "aws-sdk-cpp-pr-1333.patch"
        "Patch-cmake-submodules.patch"
        "BuildAwsCCommon.patch"
        "BuildAwsChecksums.patch")
sha256sums=('95e3f40efaea7b232741bfb76c54c9507c02631edfc198720b0e84be0ebb5e9d'
            '14abbdb71e615d93d5aa1e83f94f994b7fbe05edc63477e37325a6f5148c7278'
            'edb6ef4ac7d3e48dfc1fa4b0b02a6a191bb405ae69c19d9f7bcf3856269bc6fb'
            '957eb1cc68b151622b7667e6a13506c96fdef8f566a227ac1608c9e02d3826d3'
            '20359b6e79430d1deb69bb05214a2f18258cb54ca56e15cd24605ad0c0094df1')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/aws-sdk-cpp-pr-1333.patch"
  patch -p1 -i "${srcdir}/Patch-cmake-submodules.patch"
}

build() {
  [[ -d "${srcdir}"/build-${CARCH}-static ]] && rm -rf "${srcdir}"/build-${CARCH}-static
  mkdir -p "${srcdir}"/build-${CARCH}-static && cd "${srcdir}"/build-${CARCH}-static
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DBUILD_ONLY="config;identity-management;s3;sts;transfer" \
      -DENABLE_UNITY_BUILD=ON \
      -DAUTORUN_UNIT_TESTS=OFF \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${CARCH}-static
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
}
